package com.daka.controller;

import com.daka.annotation.Login;
import com.daka.entity.Group;
import com.daka.entity.GroupRecruit;
import com.daka.enumerate.StatusCode;
import com.daka.service.GroupRecruitService;
import com.daka.vo.response.DataResponseVo;
import com.daka.vo.response.ListDataResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * @author beliveli on 2016/3/31 0031.
 */
@Controller
@RequestMapping("/groupRecruit")
@Slf4j
public class GroupRecruitController {

    @Resource(name = "groupRecruitService")
    private GroupRecruitService groupRecruitService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/list", consumes = "application/json")
    @Login
    public ListDataResponseVo<GroupRecruit> list() {
        List<GroupRecruit> topicList = groupRecruitService.selectAll();
        return new ListDataResponseVo<GroupRecruit>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), topicList);
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/info", consumes = "application/json")
    @Login
    public DataResponseVo<GroupRecruit> info(@Valid @RequestBody Group group) {

        GroupRecruit result = groupRecruitService.selectById(group.getId());

        if (result == null) {
            return new DataResponseVo<GroupRecruit>(StatusCode.JAVA_THROW_EXCEPTION.getStatusCode(), StatusCode.JAVA_THROW_EXCEPTION.getStatusMessage());
        }

        return new DataResponseVo<GroupRecruit>(StatusCode.SUCCESS.getStatusCode(), StatusCode.SUCCESS.getStatusMessage(), result);
    }
}
